'''
商户管理相关测试
'''
from selenium.webdriver.common.by import By

from Lib.base.page_object.attendance.leave import LeaveCase
import allure
from Lib.common.assert_class import AssertClass
import pytest
from Lib.common.get_data_by_mysql import MysqlAssert


@pytest.fixture(scope='class', autouse=True)
@pytest.mark.usefixtures('login')
def set_cls(login):
    TestLeave.assertClass = AssertClass(login)
    TestLeave.leaveCase = LeaveCase(login)


@pytest.mark.skip
@allure.feature("请假管理管理测试")
class TestLeave:

    @allure.title('筛选请假列表')
    def test_leave_list(self, login):
        '''
        根据筛选条件筛选请假列表
        :param login:
        :return:
        '''
        with allure.step('根据请假类型进行筛选'):
            # 调用页面操作方法
            self.leaveCase.leave_list_leave_type()
            # 断言
            assert_args = (
                By.XPATH, '//tbody/tr/td[2]//div[contains(text(), "申请人kb") and contains(@class, "reference")]')
            self.assertClass.make_assert_by_elements_text(args=assert_args, assert_data='申请人kb')
        with allure.step("根据审批状态进行筛选"):
            self.leaveCase.leave_list_leave_status()
            assert_args = (By.XPATH, '//tbody/tr/td[9]//span[text()="已通过"]')
            self.assertClass.make_assert_by_elements_text(args=assert_args, assert_data='已通过')
        with allure.step('根据时间进行列表筛选'):
            self.leaveCase.leave_list_by_time()
            assert_args1 = (By.XPATH, '//tbody/tr[1]/td[8]//span')
            assert_args2 = (By.XPATH, '//tbody/tr[2]/td[8]//span')
            self.assertClass.make_assert_by_compare_time(args1=assert_args1, args2=assert_args2, context="根据时间查看请假")

    @allure.title('搜索请假并查看详情')
    def test_leave_search_and_detail(self):
        '''
        搜索请假、并查看请假详情
        :return:
        '''
        with allure.step('根据关键词搜索请假'):
            self.leaveCase.leave_search()
            assert_args = (
                By.XPATH, '//tbody/tr/td[2]//div[contains(text(), "申请人kb") and contains(@class, "reference")]')
            self.assertClass.make_assert_by_elements_text(args=assert_args, assert_data='申请人kb', context="查看请假列表")
        with allure.step('查看请假详情'):
            self.leaveCase.leave_detail()
            assert_args = (By.XPATH, '//div[@class="leave-management"]//div[contains(text(), "已通过")]')
            self.assertClass.make_assert_by_elements_text(args=assert_args, assert_data='已通过', context="查看请假列表")


if __name__ == '__main__':
    pytest.main(
        ['-v', '-s', './leave_test.py::TestLeave'])
    # pytest.main(['-v', './business_test.py', '--alluredir', '../result', '--clean-alluredir'])
    # os.system(r'copy ..\config\environment.properties ..\result\environment.properties')
    # os.system('allure generate  ../result -o ../report/ --clean')
